$(document)
		.ready(
				function(){
					
					selectNeonateDiseaseControl();
					
});

function selectNeonateDiseaseControl(){
	 $.each($("input[id^='neonateDiseaseFormControl-']"),function(i,item) {
						$(item)
								.keyup(function(event) {
									var selectId = $(item).attr("id");
									var selectRealId= "";
									// 获取后面的id
									if (selectId.indexOf("-") != -1) {
										selectRealId = selectId.split("-")[1];
									}
									var jq_search_suggest = $("#search_suggest"
											+ selectRealId);
									var pinyinReg = /^[a-zA-Z]*$/;
									var bianhaoReg = /^[a-zA-Z]\d*.?\d*$/;
									var bianhaoReg2 = /^\d*.?\d*$/;
									var getVal = this.value;
									if (getVal
											&& getVal.length > 1) {
										var type = 4;
										if (pinyinReg
												.exec(getVal)) {
											// 拼音的时候
											type = 1;
											getVal = getVal
													.toUpperCase();
										} else if (bianhaoReg
												.exec(getVal)
												|| bianhaoReg2
														.exec(getVal)) {
											// 编号时
											getVal = getVal
													.toUpperCase();
											type = 3;
										} else {
											// 其他情况
											type = 2;
										}
										if (getVal.length > 1) {
											$
													.post(
															'../baseinfo/queryDisease',
															{
																queryValueType : type,
																queryValue : getVal
															},
															function(
																	data) {
																if (typeof (data) == "string") {
																	alert(data);
																	return false;
																}
																jq_search_suggest
																		.empty();
																xunhuanZiDian2(
																		data,
																		jq_search_suggest);
																// /////////////////////////////////////下按事件

																jq_search_suggest
																		.addClass(
																				"divscroll300 search_suggest")
																		.show();
																$("#neonateDiseaseCode"+ selectRealId).val("");
																$("#neonateDiseaseName"+ selectRealId).val("");
															},
															'json');
										} else {
											$("#neonateDiseaseCode"+ selectRealId).val("");
											$("#neonateDiseaseName"+ selectRealId).val("");
											jq_search_suggest.hide();
										}
									} else {
										$("#neonateDiseaseCode-"+ selectRealId).val("");
										$("#neonateDiseaseName-"+ selectRealId).val("");
										jq_search_suggest.hide();
									}
									function xunhuanZiDian2(
											data, com) {
										com.empty();
										
										var rowNum = 1;
										for ( var index in data) {
											var Obj = data[index];
											var code = Obj.code;
											var name = Obj.name;
											
											var opt = $("<div>").attr('code',code).attr('name',name).text(code+ "-"+ name).addClass("suggest_link");
											opt.mouseover(
															function() {
																var divOpts = $("div[rowNum][ck='ck']");
																divOpts
																		.attr(
																				"ck",
																				"");
																$(
																		this)
																		.addClass(
																				"suggest_link_over")
																		.attr(
																				"ck",
																				"ck");

															})
													.mouseout(
															function() {
																$(
																		"div[rowNum][ck]")
																		.removeClass(
																				"suggest_link_over");
																;
																$(
																		this)
																		.removeClass(
																				"suggest_link_over");
																$(
																		this)
																		.addClass(
																				"suggest_link");
															})
													.click(
															function() {
																// 获取值
																var selectDivObj = $(this);
																var code = selectDivObj
																		.attr("code");
																var diaeaseName = selectDivObj.attr("name");
																var text = selectDivObj
																		.text();
																
																// 赋值
																$("#neonateDiseaseCode"+ selectRealId).val(code);
																$("#neonateDiseaseName"+ selectRealId).val(diaeaseName);
																$(
																		"#neonateDiseaseFormControl-"
																				+ selectRealId)
																		.val(
																				text);
																$(
																		"#neonateDiseaseFormControl-"
																				+ selectRealId)
																		.focus();
																
																
																// //////////////判断逻辑end////////////////
																
																
																// 隐藏显示层
																jq_search_suggest
																		.hide();
															});
											com.append(opt);
										}
									}
								});
						// ////////////////////////////编码制空---------2014-01-24
//						diseaseFormControl
//								.blur(function() {
//									var thisInput = $(this);
//									var shiVal = thisInput
//											.val();
//								});
					});
}


function changeObstetricalRecord(){
	var count = $("#obstetricalRecordCount").val();
	for(var i=0;i<count;i++){
		(function(i){
			$("select[name='obstetricalRecords["+i+"].fetusPositionId']").change(function(){
				if($("select[name='obstetricalRecords["+i+"].fetusPositionId'] option:selected").val()!=""){
					var name=$("select[name='obstetricalRecords["+i+"].fetusPositionId'] option:selected").text();
					$("input[name='obstetricalRecords["+i+"].fetusPositionName']").val(name);
				}else{
					$("input[name='obstetricalRecords["+i+"].fetusPositionName']").val("");
				}
				
			});
			
			$("select[name='obstetricalRecords["+i+"].childBirthId']").change(function(){
				if($("select[name='obstetricalRecords["+i+"].childBirthId'] option:selected").val()!=""){
					var name=$("select[name='obstetricalRecords["+i+"].childBirthId'] option:selected").text();
					$("input[name='obstetricalRecords["+i+"].childBirthName']").val(name);
				}else{
					$("input[name='obstetricalRecords["+i+"].childBirthName']").val("");
				}
				
			});
			
			$("select[name='obstetricalRecords["+i+"].sexId']").change(function(){
				if($("select[name='obstetricalRecords["+i+"].sexId'] option:selected").val()!=""){
					var name=$("select[name='obstetricalRecords["+i+"].sexId'] option:selected").text();
					$("input[name='obstetricalRecords["+i+"].sexName']").val(name);
				}else{
					$("input[name='obstetricalRecords["+i+"].sexName']").val("");
				}
		
			});
		})(i);
	}
}